﻿using Sidvall.Serialization;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace Sidvall.UI.Uwp.Converters
{
    public class StringToAssetConverter : IValueConverter
    {
        #region Public Members

        #region FileExtension

        private string _FileExtension = ".png";
        public string FileExtension
        {
            get
            {
                return _FileExtension;
            }
            set
            {
                _FileExtension = value;
            }
        }

        #endregion
        #region Size

        private string _Size = "24";
        public string Size
        {
            get
            {
                return _Size;
            }
            set
            {
                _Size = value;
            }
        }

        #endregion

        #region Convert

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            string size;

            if (!string.IsNullOrWhiteSpace(this.Size))
                size = "-" + this.Size;
            else
                size = string.Empty;
            switch (Application.Current.RequestedTheme)
            {
                case ApplicationTheme.Dark:
                    return "ms-appx:///Assets/Dark/" + value.ToString(string.Empty) + size + this.FileExtension;
                default:
                    return "ms-appx:///Assets/Light/" + value.ToString(string.Empty) + size + this.FileExtension;
            }
        }

        #endregion
        #region ConvertBack

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotSupportedException();
        }

        #endregion

        #endregion
    }
}
